//
//  UIViewController+LHCustom.m
//  Loohoo
//
//  Created by 陈镇 on 2024/10/19.
//

#import "UIViewController+LHCustom.h"

@implementation UIViewController (LHCustom)

+ (void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
//    initWithNibName:(nullable NSString *)nibNameOrNil bundle:(nullable NSBundle *)nibBundleOrNil

        ExchangeImplementations([UIViewController class], @selector(viewWillAppear:), @selector(lh_viewWillAppear:));
        ExchangeImplementations([UIViewController class], @selector(initWithNibName:bundle:), @selector(sl_initWithNibName:bundle:));
        
    });
}
//+(void)load{
//    
//    Method oldMethod = class_getInstanceMethod(self, @selector(viewWillAppear:));
//    Method newMethod = class_getInstanceMethod(self, @selector(lh_viewWillAppear:));
//    method_exchangeImplementations(oldMethod, newMethod);
//
//
//    Method oldMethod1 = class_getInstanceMethod(self, @selector(init));
//    Method newMethod1 = class_getInstanceMethod(self, @selector(sl_init));
//    method_exchangeImplementations(oldMethod1, newMethod1);
//    
//}

-(instancetype)sl_initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    UIViewController *vc =  [self sl_initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    vc.hidesBottomBarWhenPushed = YES;
    return vc;
}

//-(instancetype)sl_init{
//    
//    UIViewController *vc =  [self sl_init];
//    vc.hidesBottomBarWhenPushed = YES;
//    return vc;
//}

-(void)setLh_navigationHidden:(BOOL)lh_navigationHidden{
    objc_setAssociatedObject(self, @"lh_navigationHidden", @(lh_navigationHidden), OBJC_ASSOCIATION_ASSIGN);
}
-(BOOL)lh_navigationHidden{
    return  objc_getAssociatedObject(self, @"lh_navigationHidden");
}

- (void)lh_viewWillAppear:(BOOL)animated {
    [self lh_viewWillAppear:animated];
    
    
    if ([self isBlackList]) {
 
        [self.navigationController setNavigationBarHidden:self.lh_navigationHidden animated:animated];

    }
}

//需要处理的
-(BOOL)isBlackList{
    if ([self isKindOfClass:[ QMUICommonViewController class]]) {
        return YES;
    }
    if ([NSStringFromClass(self.class) hasPrefix:@"TUI"]) {
        return YES;
    }
    return NO;
}
@end

